#version 430 core

#define LOC_X 16
#define LOC_Y 16

#define GRID_SIZE_X 64
#define GRID_SIZE_Y 64
#define UNIT_OFFSET_X 1.f/(GRID_SIZE_X+1)
#define UNIT_OFFSET_Y 1.f/(GRID_SIZE_Y+1)

layout(local_size_x=LOC_X, local_size_y=LOC_Y) in;

layout(binding=0, rgba32f) uniform readonly image2D jumpFloodingSrc;
layout(binding=1, rg32f) uniform image2D velocityImage;

void main(void)
{
	ivec2 gid = ivec2(gl_GlobalInvocationID.xy);
	if (gid.x <= GRID_SIZE_X && gid.y <= GRID_SIZE_Y)
	{
		vec3 jumpFloodingLookup = imageLoad(jumpFloodingSrc, gid).xyz;
		if (jumpFloodingLookup.x > 0.0f)
		{
			vec2 velGet = imageLoad(velocityImage, ivec2(jumpFloodingLookup.yz)).xy;
			imageStore(velocityImage, gid, vec4(velGet, 0.f, 1.f));
		}
	}
}